import * as echarts from 'echarts'
import { dateFormat } from '@/utils/functions.ts'
import { max } from 'lodash'
const today = new Date() -1
const thisyear = new Date().getFullYear()
let from = new Date(thisyear + "/01/01") -1
const end = new Date((thisyear+1) + "/01/01") -1
const oneday = 3600 * 24 * 1000;
const hotdata = []
const linedata = []
const linex = []
const ctlinedata = []
while(from <= today+oneday){
  const date = dateFormat('YYYY-MM-DD',from)
  const value = Math.floor(Math.random() * 1000)
  linex.push(date)
  linedata.push(value)
  hotdata.push([date,value])
  ctlinedata.push( Math.floor(Math.random() * 15))
  from += oneday
}
// while(from <= end){
//   hotdata.push([dateFormat('YYYY-MM-DD',from),0])
//   from += oneday
// }

const maxV = Math.ceil(max(linedata)/100)*100
const maxV2 = Math.ceil(max(ctlinedata)/10)*10
export const hotoption = {
  title: {
    top: 30,
    left: 30,
    text: 'SRC-用户访问量'
  },
  tooltip:{
    trigger:'item',
    formatter:({data:[date,value]})=>{
      return `日期：${date}<br >访问量：${value}`
    }
  },
  visualMap: {
    min: 0,
    max: maxV,
    type: 'piecewise',
    orient: 'horizontal',
    left: 30,
    top: 65
  },
  calendar: {
    top: 120,
    left: 30,
    right: 30,
    cellSize: ['auto', 25],
    range: thisyear,
    itemStyle: {
      borderWidth: 0.5
    },
    yearLabel: { show: false }
  },
  series: {
    type: 'effectScatter',
    coordinateSystem: 'calendar',
    data: hotdata
  }
}

export const lineoption = {
  tooltip: {
    trigger: 'axis',
    position: function (pt) {
      return [pt[0], '10%'];
    }
  },
  title: {
    left: 30,
    text: '日用户访问量'
  },
  toolbox: {
    feature: {
      dataZoom: {
        yAxisIndex: 'none'
      },
      restore: {},
      saveAsImage: {}
    }
  },
  xAxis: {
    type: 'category',
    boundaryGap: false,
    data: linex
  },
  yAxis: {
    type: 'value',
    boundaryGap: [0, '100%'],
    max:maxV
  },
  dataZoom: {
    type:'inside',
    start: 0,
    end: 30
  },
  series: [
    {
      name: '访问量',
      type: 'line',
      symbol: 'none',
      itemStyle: {
        color: 'rgb(255, 70, 131)'
      },
      areaStyle: {
        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
          {
            offset: 0,
            color: 'rgb(255, 158, 68)'
          },
          {
            offset: 1,
            color: 'rgb(255, 70, 131)'
          }
        ])
      },
      data: linedata
    }
  ]
};

export const ctline = {
  visualMap:{
    show: false,
    type: 'continuous',
    seriesIndex: 0,
    min: 0,
    max: maxV2
  },
  title:{
    left: 30,
    text: '日发布比赛数量'
  },
  tooltip: {
    trigger: 'axis'
  },
  xAxis:{
    data: linex
  },
  dataZoom: {
    start: 0,
    end: 30,
    type:'inside',
  },
  yAxis:{
    max:maxV2
  },
  series: [
    {
      name: '比赛发布数量',
      type: 'line',
      showSymbol: false,
      data: ctlinedata
    },
  ]
}